use crate::conf::config;

#[derive(Debug, Deserialize, Serialize)]
pub struct Rooms {
    pub room_count: u16,
    pub room_size:u16,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct Global {
    pub log_level: String,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct DB {
    pub pg_url: String,
    pub max_conn: u32,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct Server {
    pub addr_and_port: String,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct Email {
    pub host: String,
    pub port: String,
    pub smtp_user: String,
    pub smtp_pawd: String,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct Config {
    pub global: Global,
    pub server: Server,
    pub db: DB,
    pub email: Email,
    pub rooms:Rooms,
}

impl Config {
    pub fn new(path: &'static str) -> Result<Self, String> {
        let cres: Result<Config, config::Error> =
            config::load_config_from_path(config::File::new(path));
        match cres {
            Err(e) => Err(e.error()),
            Ok(o) => Ok(o),
        }
    }
}
